home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 69 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.6 KB

  1. Path: fido.asd.sgi.com!austern
  2. From: clamage@Eng.Sun.COM (Steve Clamage)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Throwing an exception from within a si
  5. Date: 18 Jan 1996 10:19:59 PST
  6. Organization: Sun Microsystems Inc.
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4dltnb$mca@engnews1.Eng.Sun.COM>
  9. References: <4dka2t$p6m@galaxy.ucr.edu>
  10. Reply-To: clamage@Eng.Sun.COM
  11. NNTP-Posting-Host: isolde.mti.sgi.com
  12. X-Original-Date: 18 Jan 1996 16:49:47 GMT
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMP6PdEy4NqrwXLNJAQGVWAH/Q5EobLwSWfjKw14WdjnF2AilqtlUGVJ+
  15.     PUACll/WdgpmkBvRlnvwl1HaiWo9mDSKfrT56aigb/TOrHLYg6ljQQ==
  16.     =gs/Q
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. In article p6m@galaxy.ucr.edu, thp@cs.ucr.edu (Tom Payne) writes:
  20. >Steve Clamage (clamage@Eng.Sun.COM) wrote:
  21. >: In article 22h@galaxy.ucr.edu, thp@cs.ucr.edu (Tom Payne) writes:
  22. >: >why shouldn't signal
  23. >: >handlers be allowed to throw exceptions? 
  24. >: 
  25. >: Exceptions are synchronous, and unwind the stack from the point of the 
  26. >: throw to the point of the handler. When an asynchronous signal arrives,
  27. >: what is the state of the stack? Answer: unknown. In particular, the
  28. >: stack might not even be in a consistent state -- arguments half pushed
  29. >: during function entry or half popped during exit.
  30. >
  31. >When accessing any critical, shared data structure, it is standard
  32. >practice to exclude interrupt-sustained pseudothreads (signal
  33. >handlers) that access the same structure by blocking their
  34. >corresponding signal.  The overhead should be minimal.
  35.  
  36. In time-critical programs on real-time systems, yes, locking overhead
  37. needs to be minimal. Remember we are talking about the C++ language spec,
  38. not an operating system spec. More below.
  39.  
  40. >: Allowing exceptions to be thrown from a signal handler would place a
  41. >: noticeable penalty on all programs to provide locks on every function
  42. >: entry and exit, even programs that didn't throw exceptions or use
  43. >: signals.
  44. >
  45. >I'm not sure.  Signal blocking is required only in cases where signal
  46. >handlers might collide with interrupted code over a critical, shared data
  47. >structure.  But, independently compiled libraries must be prepared for
  48. >the worst case.
  49.  
  50. Suppose that function entry and exit are not atomic operations, which is
  51. the case on all systems supporting C++ that I am aware of. The "critical
  52. structure" is the stack frame. If asynchronous interrupts can occur, and
  53. if you are going to require well-defined exception behavior from signal
  54. handlers, then you must lock the entirety of every function preamble and
  55. postamble. (You cannot know that an external signal won't occur.) That
  56. requirement not only slows down function calls, it adds to interrupt
  57. latency.
  58.  
  59. How expensive is it to lock and unlock every function entry and exit?
  60. On some systems it is cheap. On others it is expensive. Considering that
  61. a characteristic of OO programs is having many small functions, requiring
  62. these locks could have a dramatic impact on program performance, even
  63. for programs that don't want to throw exceptions from signal handlers.
  64.  
  65. What we put in the language standard is binding on all implementations. We
  66. try to specify things that can be implemented efficiently on any likely
  67. system. In addition, we try to specify features so that they have no cost
  68. (or nearly no cost) if you don't use them. IMHO, guarantees about what you
  69. can do in an asynchronous signal handler don't meet those criteria for
  70. inclusion in the C++ standard.
  71. ---
  72. Steve Clamage, stephen.clamage@eng.sun.com
  73. ---
  74. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  75.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  76.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  77.